<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateOrdersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('orders', function (Blueprint $table) {
            $table->id()->comment('订单表');
            $table->integer('user_id')->index()->comment('用户id');
            $table->integer('mer_id')->index()->comment('商户ID');
            $table->integer('cart_id')->index()->comment('购物车id');
            $table->integer('store_id')->index()->comment('门店id');
            $table->integer('clerk_id')->index()->comment('店员id');
            $table->integer('promoter_id')->nullable()->comment('推广员id');
            $table->integer('seckill_id')->index()->nullable()->comment('秒杀id');
            $table->integer('bargain_id')->index()->nullable()->comment('砍价id');
            $table->integer('delivery_uid')->index()->nullable()->comment('配送员id');
            $table->integer('coupon_id')->index()->default(0)->comment('优惠券id');
            $table->integer('pink_id')->index()->nullable()->comment('拼团id');
            $table->string('order_number')->index()->comment('订单号');
            $table->string('type')->default('ordinaryOrder')->comment('订单类型:
                ordinaryOrder : 普通订单, pinkOrder : 拼团订单, seckillOrder : 秒杀订单, bargainOrder : 砍价订单');
            $table->string('user_name',32)->index()->comment('收货人姓名');
            $table->string('user_phone',32)->index()->comment('收货人电话');
            $table->string('user_address')->comment('详细地址');
            $table->decimal('freight_price',8,2)->default(0)->comment('运费金额');
            $table->integer('total_num')->comment('订单商品总数');
            $table->decimal('total_price',8,2)->comment('订单总价(分)');
            $table->decimal('total_postage',8,2)->default(0)->comment('邮费(分)');
            $table->decimal('pay_price',8,2)->comment('实际支付金额(分)');
            $table->decimal('pay_postage',8,2)->default(0)->comment('支付邮费(分)');
            $table->decimal('deduction_price',8,2)->default(0)->comment('抵扣金额(分)');
            $table->decimal('coupon_price',8,2)->default(0)->comment('优惠券金额(分)');
            $table->timestamp('pay_time')->nullable()->comment('支付时间');
            $table->string('pay_type')->comment('支付方式 wechat:微信支付 alipay:支付宝支付 余额支付:balance 线下支付:offline');
            $table->string('status',20)->default('noBePaid')->comment('订单状态(
            noPaid 未支付, noDelivered 未发货; toBeReceived 待收货; toBeEvaluated 待评价; dealDone 交易完成;
            toBeWriteOff 待核销, writtenOff 已核销');
            $table->string('refund_status',20)->nullable()->comment('退款状态:
            Refund_only 仅退款, Refund_return 退款退货, Refuse_refund 拒绝退款, toBe_returned 商品待退货, toBe_received 退货待收货, refunded 已退款');
            $table->string('refund_reason_wap_img')->nullable()->comment('退款图片');
            $table->string('refund_reason_wap_explain')->nullable()->comment('退款用户说明');
            $table->string('mark')->nullable()->comment('用户备注');
            $table->timestamp('refund_reason_time')->nullable()->comment('退款时间');
            $table->string('refund_reason_wap')->nullable()->comment('前台退款原因');
            $table->string('refund_reason')->nullable()->comment('不退款原因');
            $table->decimal('refund_price',8,2)->nullable()->comment('退款金额(分)');
            $table->string('delivery_name')->comment('快递名称/送货人姓名');
            $table->string('delivery_code')->comment('快递公司编码');
            $table->string('delivery_type')->comment('发货类型');
            $table->string('delivery_id')->comment('快递单号/手机号');
            $table->string('sender_name')->nullable()->comment('寄件人姓名');
            $table->string('sender_phone')->nullable()->comment('寄件人电话');
            $table->string('sender_address')->nullable()->comment('寄件人地址');
            $table->string('fictitious_content')->nullable()->comment('虚拟发货内容');
            $table->decimal('gain_integral',8,2)->comment('消费赚取积分');
            $table->decimal('use_integral',8,2)->comment('使用积分');
            $table->decimal('back_integral',8,2)->comment('给用户退了多少积分');
            $table->string('unique')->comment('唯一id(md5加密)类似id');
            $table->string('remark')->nullable()->comment('管理员备注');
            $table->decimal('cost')->comment('成本价(分)');
            $table->string('verify_code')->comment('核销码');
            $table->string('channel_type')->nullable()->comment('用户访问端标识');
            $table->string('province')->nullable()->comment('用户省份');
            $table->string('express_dump')->nullable()->comment('订单面单打印信息');
            $table->tinyInteger('paid')->default(0)->comment('支付状态 0 = 未支付 1 = 已支付');
            $table->tinyInteger('is_user_delete')->default(0)->comment('用户是否删除订单 0 = 未删除 1 = 已删除');
            $table->tinyInteger('is_remind')->default(0)->comment('是否已经消息提醒 0 = 未提醒 1 = 已提醒');
            $table->tinyInteger('shipping_type')->default(0)->comment('配送方式 0 = 快递 , 1 = 门店自提');
            $table->tinyInteger('is_mer_check')->default(0)->comment('是否核销 0 = 未核销, 1 = 已核销');
            $table->softDeletes();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('orders');
    }
}
